#!/usr/bin/python3

import sys

# col number of M
mc = int(sys.argv[1])
#mc = 3
vector = [1 for i in range(mc)]
res = 0
r = None
c = None
for line in sys.stdin:
    parts = line.split('\t')
    key = list(map(int, parts[0].split(',')))
    value = list(map(int, parts[1].split(',')))
    if r is None:
        r = key[0]
        c = key[1]
    elif key[0] != r or key[1] != c:
        for v in vector: 
            res -= v
        print("{0}\t{1}\t{2}".format(r, c, res))
        r = key[0]
        c = key[1]
        # reset values to calculate value for new location (r,c)
        res = 0
        vector = [1 for i in range(mc)]
    j = value[0]
    if j == -1:
        res += value[1]
    else:
        vector[j] = vector[j] * value[1] 

for v in vector: 
    res -= v
print("{0}\t{1}\t{2}".format(r, c, res))
